//适用于课程模块的api接口封装
import axios from './axios'
//获取所有课程数 依据的是分页查询
export const getAllCourses = (pageNum, pageSize) => {
    if(pageNum&&pageSize){
        return axios.request({
            url: '/course/getAllCourses' + '?pageNum=' + pageNum + '&pageSize=' + pageSize,
            method: 'post',
        })
    }else{
        //获取所有
        return axios.request({
            url: '/course/getAllCourses',
            method: 'post',
        })
    }
   
}
// 获取某个类别下的课程总数 category关键字可以省略
export const courseTotal = (category) => {
    if (category) {
        return axios.request({
            url: '/course/countByKey' + '?key=' + category,
            method: 'post',
        })
    } else {
        return axios.request({
            url: '/course/countByKey',
            method: 'post',
        })
    }

}
// 根据类别分页获取课程list
export const courseList = (category, currentPage, pageSize) => {
    return axios.request({
        url: '/course/fuzzyQuery' + '?key=' + category + '&pageNum=' + currentPage + '&pageSize=' + pageSize,
        method: 'post',
    }
    )
}
// 根据课程ID获取课程相关信息
export const getCourseById = (courseId) => {
    return axios.request({
        url: '/course/queryById?id=' + courseId,
        method: "post"
    })
}
//根据课程ID操作对应课程公告
//增加课程的公告 参数是一个对象 包括{context，courseId，createTime，noticeId}
export const addAnno = (anno) => {
    return axios.request({
        url: '/notice/add',
        method: 'post',
        data: anno
    }
    )
}
// 查询指定课程对应的公告数
export const countAnno = (courseId) => {
    return axios.request({
        url: '/notice/count' + '?courseId=' + courseId,
        method: 'post',
    }
    )
}
// 删除公告 只需要传入对应的公告ID
export const deleteAnnoByID = (annoId) => {
    return axios.request({
        url: '/notice/deleteById' + '?id=' + annoId,
        method: 'post',
    }
    )
}
// 修改公告
export const editAnno = (anno) => {
    return axios.request({
        url: '/notice/edit',
        method: 'post',
        data: anno
    }
    )
}

// 通过主键查询单个数据 用于管理员功能
export const queryAnnoById = (id) => {
    return axios.request({
        url: '/notice/queryById' + '?id=' + id,
        method: 'post',
    }
    )
}
// 分页查询 模拟加载更多操作 （课程ID，第几页，每一页大小）
export const queryByPage = (courseId, pageNum, pageSize) => {
    return axios.request({
        url: '/notice/queryByPage' + '?courseId=' + courseId + '&pageNum=' + pageNum + '&pageSize=' + pageSize,
        method: 'post'
    })
}
// 课程资料模块API集中管理
// 批量删除文件
export const batchDelete = (courseId, pageNum, pageSize) => {
    return axios.request({
        url: '/notice/queryByPage' + '?courseId=' + courseId + '&pageNum=' + pageNum + '&pageSize=' + pageSize,
        method: 'post'
    })
}
// 删除文件
export const deleteByPath = (dataId, objectName) => {
    return axios.request({
        url: '/courseData/delete' + '?dataId=' + dataId + '&objectName=' + objectName,
        method: 'post'
    })
}
// 删除文件夹 连同删除旗下内容
export const deleteFolder1 = (dataId, objectName) => {
    return axios.request({
        url: '/courseData/deleteFolder' + '?dataId=' + dataId + '&objectName=' + objectName,
        method: 'post'
    })
}
// 下载文件
export const download = (objectName) => {
    return axios.request({
        url: '/courseData/download' + '?objectName=' + objectName,
        method: 'post',
        headers: {
            'Content-Type': 'application/x-download'
        },
        responseType: 'blob'
    })
}
// 获取文件子目录集合 唯一参数是objectName 代表查询项目路径
export const getObjectList = (objectName) => {
    return axios.request({
        url: '/courseData/getObjectList?' + "objectName=" + objectName,
        method: 'post'
    })
}
// 课程资料 上传文件
export const upload = (formData) => {
    return axios.request({
        url: '/courseData/upload',
        method: 'post',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data;'
        }
    })
}

// 创建新的文件夹
export const newFolder = (courseData) => {
    return axios.request({
        url: "/courseData/newFolder",
        method: 'post',
        data: courseData,
    })
}

export const reName = (dataId, newName, objectName) => {
    return axios.request({
        url: "/courseData/rename" + "?dataId=" + dataId + '&newName=' + newName + '&objectName=' + objectName,
        method: "post",
    })
}
// 文件预览 需要携带生命周期的文件地址
export const fileUrl = (path) => {
    return axios.request({
        url: "/courseData/getUrl" + '?objectName=' + path,
        method: "post",
    })
}
// 获取所有章节内容
export const getChapters = (chapter) => {
    return axios.request({
        url: '/chapter/queryFuzzy',
        method: 'post',
        data: chapter
    })
}
// 获取单个小节
export const queryById = (item) => {
    return axios.request({
        url: '/chapter/queryById',
        method: 'post',
        data: item
    })
}
// 新增章节
export const addChapter = (chapter) => {
    return axios.request({
        url: '/chapter/add',
        method: 'post',
        data: chapter
    })
}

// 批量删除
export const deleteBatch = (deleteData) => {
    return axios.request({
        url: '/chapter/deleteBatch',
        method: 'post',
        data: deleteData
    })
}
// 新增课程
export const defaultAddCourse = (course, tid) => {
    return axios.request({
        url: '/course/defaultAdd?tid=' + tid,
        method: 'post',
        data: course
    })
}
// 关联老师和课程
export const linked = (cid, tid) => {
    return axios.request({
        url: '/course/linked' + '?cid=' + cid + '&tid=' + tid,
        method: 'post',

    })
}

export const uploadPublic = (file) => {
    return axios.request({
        url: '/courseData/uploadPublic',
        method: 'post',
        data: file
    })
}
// 编辑小节内容 参数包括课程id 章节id 小节id 以及章节内容（JSON格式）
export const seeionEdit = (chapter) => {
    return axios.request({
        url: '/chapter/edit',
        method: 'post',
        data: chapter
    })
}
//根据用户ID获取相关课程信息
export const queryCourseByUserId = (teacherId) => {
    return axios.request({
        url: '/studentCourse/queryByStudentId' + '?id=' + teacherId,
        method: 'post',
    })
}
// 
export const queryCourseByStuId = (stuId) => {
    return axios.request({
        url: '/studentCourse/queryByStudentId' + '?id=' + stuId,
        method: 'post',
    })
}
//根据课程ID查询课程下所有学生信息
export const queryStudentsByCid = (cId) => {
    return axios.request({
        url: '/studentCourse/queryByCourseId' + '?id=' + cId,
        method: 'post'
    })
}

//在课程中，老师主动添加一个学生加入课程

export const insertInCourse = (cid,telList) => {
    return axios.request({
        url:'/studentCourse/addByTeacher?cid='+cid+'&telList='+telList,
        method:'post',
    })
}

//根据老师ID查询所开设的课程

export const queryCourseByTeacherId = (teacherId) => {
    return axios.request({
        url: '/course/queryByTeacherId' + '?teacherId=' + teacherId,
        method: 'post',
    })
}
//根据课程id获取课程相关信息
export const getCourseMessage = (cId) => {
    return axios.request({
        url: '/course/queryById' + '?id=' + cId,
        method: 'post',
    })
}
//更新课程信息
export const updateCourseMessage = (course) => {
    return axios.request({
        url: '/course/edit',
        method: 'post',
        data: course
    })
}
//根据课程id删除课程
export const deleteCourseByCid = (cid) => {
    return axios.request({
        url: '/course/deleteById?id=' + cid,
        method: 'post',
    })
}
//根据课程id和学生id删除选课信息
export const deleteRecord=(cid,sid)=>{
    return axios.request({
        url:'/studentCourse/deleteRecord?cid='+cid+'&sid='+sid,
        method:'post'
    })
}